<template>
  <div>
    <div class="song">
      <div
        class="songbg"
        :style="{ background: `url(${SongTitle.coverImgUrl})` }"
      ></div>
      <div class="coverImg">
        <img :src="SongTitle.coverImgUrl" alt="" />
        <span>{{ SongTitle.playCount | formatPlayCount }}</span>
      </div>
      <div class="listMsg">
        <h2>{{ SongTitle.name }}</h2>
        <p>
          <img
            :src="avatarUrl"
            alt=""
            width="30"
            height="30"
          />
          <span>{{ nickName }}</span>
        </p>
      </div>
    </div>
    <h6>歌曲列表</h6>

    <div class="songlist">
      <ul class="HotList">
        <li v-for="(item, index) in SongList" :key="item.id">
          <span class="Hot-index">{{index+1}}</span>
          <songListItem
            :item="item"
            :index="index"
            :key="item.id"
            @update:music="$emit('update:music', $event)"            @update:playlist="$emit('update:playlist',SongList)"
            :currentMusic="$attrs.currentMusic"
            :paused="$attrs.paused"
          ></songListItem>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import songListItem from "./songListItem";
export default {
  components: {
    songListItem,
  },
  data() {
    return {
      SongTitle: [],
      SongList: [],
      nickName:'',
      avatarUrl:''
    };
  },
  beforeCreate(){
        this.$root.isShowLoading = true;
  },
  created() {
    this.axios
      .get("/playlist/detail", { params: { id: this.$route.query.id } })
      .then((result) => {
        console.log(result);
        this.SongTitle = result.data.playlist;
        this.nickName = result.data.playlist.creator['nickname'];
        this.avatarUrl = result.data.playlist.creator['avatarUrl'];
        let tracks = result.data.playlist.trackIds
          .map((item) => item.id)
          .slice(0, 15);

        this.axios
          .get("/song/detail", { params: { ids: tracks.join(",") } })
          .then((result) => {
            // console.log(result);
            this.SongList = result.data.songs;
        this.$root.isShowLoading = false;

          });
      });
  },
  activated(){
     this.axios
      .get("/playlist/detail", { params: { id: this.$route.query.id } })
      .then((result) => {
        console.log(result);
        this.SongTitle = result.data.playlist;
        this.nickName = result.data.playlist.creator['nickname'];
        this.avatarUrl = result.data.playlist.creator['avatarUrl'];
        let tracks = result.data.playlist.trackIds
          .map((item) => item.id)
          .slice(0, 15);

        this.axios
          .get("/song/detail", { params: { ids: tracks.join(",") } })
          .then((result) => {
            // console.log(result);
            this.SongList = result.data.songs;
          });
      });
  },
  filters: {
    formatPlayCount: function (value) {
      return (value / 10000).toFixed(1) + "万";
    },
  },
};
</script>

<style scoped lang="less">
.song {
  height: 174px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0px 10px 0px;
  .songbg {
    height: 174px;
    width: 100vw;
    filter: blur(20px);
    background-size: cover !important;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
  }
  .coverImg {
    position: relative;
    color: white;
    font-size: 12px;
    flex-basis: 114px;
    &:before {
      content: "歌单";
      position: absolute;
      left: 0;
      top: 10px;
      width: 40px;
      height: 17px;
      background: rgba(226, 6, 6, 0.7);
      border-radius: 0 20px 20px 0;
      text-align: center;
    }
    img {
      width: 114px;
    }
    span {
      position: absolute;
      right: 2px;
      top: 1px;
      &:before {
        content: "";
        background: no-repeat
          url("");
        background-position: 0 2px;
        display: inline-block;
        width: 1em;
        height: 1em;
        margin-right: 5px;
      }
    }
  }
  .listMsg {
    flex: 1;
    align-self: flex-start;
    margin-left: 15px;
    margin-top: 25px;
    h2 {
      font-size: 17px;
      color: white;
      font-weight: 300;
    }
    p {
      margin-top: 20px;
      color: #ccc;
      img {
        border-radius: 50%;
        vertical-align: middle;
        margin-right: 5px;
      }
    }
  }
}

h6 {
  background-color: #eeeff0;
  font-size: 12px;
  padding-left: 12px;
  color: #666;
  height: 23px;
  line-height: 23px;
}
</style>